cmake_minimum_required(VERSION 3.0.2)
project(senyun_driver)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  nodelet
  module_base
  roscpp
  rospy
  sensor_msgs
  qomolo_msgs
)

find_package( OpenCV REQUIRED )
find_package( CUDA REQUIRED )

set(CUDA_NVCC_FLAGS
  ${CUDA_NVCC_FLAGS};
  -O3 -lineinfo
  )

catkin_package(
 INCLUDE_DIRS include
)

include_directories(
 include
  ${catkin_INCLUDE_DIRS}
  /usr/local/cuda/targets/aarch64-linux/include
  /opt/vpi1/include/
)
link_directories(/usr/local/cuda/targets/aarch64-linux/lib
              /opt/vpi1/lib64/)

set (CU_SRC_FILES
  src/yuyv2rgb.cu
  src/undistort.cu
)

list(APPEND CUDA_NVCC_FLAGS "-Xcompiler;-fPIC;-DVERBOSE")

CUDA_COMPILE(cuda_objs ${CU_SRC_FILES})
cuda_add_library(senyun_driver SHARED src/senyun_driver.cpp src/gmsl_camera_handler.cpp ${cuda_objs})
target_link_libraries(senyun_driver
  ${OpenCV_LIBS} pthread cudart ${CUDA_npp_LIBRARY} libnppim.so libnppicc.so libnppisu.so libnvvpi.so
)

install(TARGETS
        senyun_driver
        RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        )
 ## 安装相关头文件
 install(DIRECTORY include/senyun_dri
         DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
         FILES_MATCHING PATTERN "*.h"
                        PATTERN "*.hpp"
                        PATTERN "*.svn"
                        )
 ## 安装功能包的launch file目录到制定目录
 install(DIRECTORY launch/
     DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
     FILES_MATCHING PATTERN "*.launch"
   )
 
 ## 安装功能包的其他文件到指定目录
 install(FILES nodelet_plugins.xml
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
   )
